package com.sk.controller;

import com.sk.constant.Constants;
import com.sk.mapper.SProjectMapper;
import com.sk.pojo.RespBean;
import com.sk.pojo.SProject;
import com.sk.server.ProjectServer;
import com.sk.service.impl.SProjectServiceImpl;
import com.sk.utils.FdfsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("project")
public class ProjectController {
    String ip = Constants.IP;
    @Autowired
    FdfsUtils fastDFSUtil;

    @Autowired
    ProjectServer projectServer;

    @Autowired
    SProjectMapper sProjectMapper;

    @PostMapping("add")
    public RespBean add(@RequestParam("name") String name, @RequestParam("username")
    String username, String content, MultipartFile file, String mainPro, Integer score) {
        return projectServer.add(name, username, content, file, mainPro, score, ip);
    }

    @PostMapping("delete")
    public RespBean delete(Integer id) {
       return projectServer.delete(id);
    }

    @PostMapping("like")
    public RespBean like(String name) {
        List<SProject> like = projectServer.like(name);
        return RespBean.success("查找成功", like);
    }

    @PostMapping("update")
    public RespBean update(@RequestParam("id") Integer id, String name, String username,
                           String content, MultipartFile file, String mainPro, Integer score) {
        return projectServer.update(id, name, username, content, file, mainPro, score, ip);
    }


}
